home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / util / wb / THE.lha / T.H.E. / Prefs / THE < prev   
Encoding:
Text File  |  1999-10-31  |  27.5 KB  |  860 lines

  1. /*
  2.    $VER: RA_THE.rexx 1.0 (30.10.99) Copyright (c) Nils Görs.
  3.  
  4.    Thanks to William Parker for writing AWNP and for teaching me how to
  5.    use it.
  6.  
  7.    This script is for editing the Tools-Menu and Hotkey functions from Workbench.
  8.  
  9.    The script creates an ARexx-Script that will be placed in WBStartup. You have
  10.    to create an Icon for this script to be executed automatically.
  11.  
  12.    This script needs:
  13.     - AWNPipe: ver 2.18 or newer.
  14.     - workbench.library v44.1414 or newer.
  15. */
  16.  
  17. Scriptname = "Sys:WBStartup/setKeyAndMenu.rexx"
  18. /*
  19. *** Please don't change anything under this line
  20. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  21. options results
  22.  
  23. parse source . . called .
  24. PARSE ARG PubScreen
  25. IF PubScreen = "" THEN PubScreen = "Workbench"
  26.  
  27. ADDRESS workbench
  28.  
  29. ca = "THE"
  30.  
  31. call _InitAll()
  32. call BuildGUI()
  33.  
  34. Loop:
  35. do while ~eof(ca)
  36. call topipe('con')
  37. in= readln(ca)
  38.  
  39. /*listviews need five values parsed. For string gadgets you want everything after in2 */
  40. parse var in in1 in2 in3 in4 in5 .
  41. parse var in . . infromstring
  42.  
  43. if in1='iconify' then call iconify()
  44. if in1='gadget' then call gadget()
  45. if in1='menu' then call menu()
  46. if in1='close' then EXIT()
  47. end
  48. EXIT
  49.  
  50. _InitAll:
  51. IF ~show('L','rexxsupport.library') THEN
  52. IF ~addlib('rexxsupport.library',0,-30,0) THEN
  53. exit(20)
  54.  
  55. /* Version check */
  56. IF SHOWLIST('H', 'AWNPIPE') THEN res=open(ca,"awnpipe:T.H.E./-2019/xc")
  57.     if res ~= 1 then do
  58.         requesterdata='`requestchoice "T.H.E. Error"
  59. "To use this program you need AWNPipe:*n        (Vers 2.18 or newer). " "OK"`'
  60.         CALL ShellResult(requesterdata)
  61.         exit
  62.     end
  63.  
  64. checkversion = '`version workbench.library`'
  65. IF WORD(ShellResult(checkversion),2) < "44.1414" THEN DO
  66.         requesterdata='`requestchoice "T.H.E. Error"
  67.  "To use this program you need OS 3.5*n      (Vers 44.1414 or newer). " "OK"`'
  68.         CALL ShellResult(requesterdata)
  69.         EXIT
  70. END
  71.  
  72.  
  73. /* Init variables */
  74. TRUE  = 1
  75. FALSE = 0
  76. NL = '0a'x
  77. TM_entries = ""
  78. HK_Entries = ""
  79. TM_STRINGNAMEVALUE = ""
  80. TM_STRINGTITLEVALUE = ""
  81. TM_STRINGSHORTCUTVALUE = ""
  82. TM_StringCommandValue    = "rexx:"
  83. TM_StringArgumentValue    = ""
  84.  
  85. HK_StringNameValue = ""
  86. HK_StringHotkeyValue = ""
  87. HK_StringCommandValue    = "rexx:"
  88. HK_StringArgumentValue    = ""
  89.  
  90. HK_counter = 0
  91. TM_counter = 0
  92.  
  93. currentpage = 0
  94.  
  95. Hotkeys = "SHIFT|LSHIFT|RSHIFT|AMIGA|LAMIGA|RAMIGA|ALT|LALT|RALT|ESC|RETURN|DEL|HELP|CTRL|CAPSLOCK|NUMERICPAD|ENTER|BACKSPACE|SPACE|COMMA|UPSTROKE"
  96.  
  97. /*
  98. ** Set current dir
  99. */
  100.  
  101.  PARSE SOURCE . . . progdir .
  102.  
  103.  booll = LENGTH(progdir)
  104.  booli= LASTPOS(":",progdir)
  105.  boolh= LASTPOS("/",progdir)
  106.  
  107.  
  108. IF boolh > booli THEN progdir = SUBSTR(progdir,1,boolh-1)
  109. IF boolh == 0 THEN progdir = SUBSTR(progdir,1,booli)
  110.  
  111. IF RIGHT(progdir,1) ~= ':' THEN progdir2 = progdir||'/'
  112.             ELSE progdir2 = progdir
  113.  
  114.  CALL PRAGMA('D',progdir)
  115.  
  116. /*
  117. ** Read default strings, open locale.library and catalog
  118. */
  119.  
  120. IF ~loadrexx(progdir,'THE.strings','') THEN
  121.    quit('Error reading file "THE.strings"!',10)
  122.  
  123. IF ~SHOW('LIBRARIES','locale.library') THEN
  124.    CALL ADDLIB('locale.library',0,-30,0)
  125.  
  126. IF SHOW('LIBRARIES','locale.library') THEN DO
  127.     id='req'pragma('id')                /* get current language */
  128.     address command 'rxset' id '`echo $language`' 
  129.     language=getclip(id)
  130.     call setclip(id,'')
  131.  
  132.    IF language ~= '' THEN
  133.       catalog = OPENCATALOG(progdir2'catalogs/'language'/THE.catalog','english',0)
  134.  
  135.    IF catalog = 0 THEN
  136.       catalog = OPENCATALOG('THE.catalog','english',0)
  137.  
  138. END
  139.  
  140. RETURN
  141.  
  142. /*******************************************************************************
  143. ** Load and interpret arexx script
  144. *******************************************************************************/
  145.  
  146. loadrexx:
  147.    PARSE ARG dir,file,store
  148.  
  149.    IF dir ~= '' THEN DO
  150.       IF RIGHT(dir,1) = ':' THEN
  151.          file = dir||file
  152.       ELSE
  153.          file = dir||'/'||file
  154.    END
  155.  
  156.    IF ~OPEN('rexxfile',file,'R') THEN
  157.       RETURN(FALSE)
  158.  
  159.    rexxtext = READCH('rexxfile',64000)
  160.    INTERPRET rexxtext
  161.  
  162.    CALL CLOSE('rexxfile')
  163.  
  164.    IF store ~= '' THEN
  165.       INTERPRET store '= rexxtext'
  166.  
  167.    DROP rexxtext
  168.  
  169.    RETURN(TRUE)
  170.  
  171. /*******************************************************************************
  172. ** Text aus dem Catalog-File auslesen, falls vorhanden
  173. *******************************************************************************/
  174.  
  175. localestring:
  176.    PARSE ARG stringnumber
  177.  
  178.    IF catalog ~= 0 THEN
  179.       RETURN(GETCATALOGSTR(catalog,stringnumber,strings.stringnumber))
  180.    ELSE
  181.       RETURN(strings.stringnumber)
  182.  
  183. /*
  184. ***
  185. */
  186. iconify:
  187. IF in2=1 THEN call topipe('id 0 s 32')        /* iconify   */
  188.      ELSE call topipe('id 0 s 64')        /* uniconify */
  189. RETURN
  190.  
  191. menu:
  192.     IF in2 = 0 & in3 = 0 THEN DO
  193.         requesterdata='`requestchoice "RA_THEinfo" "RA_THE.rexx 1.0 (30.10.99)*n©1999 by Nils Görs*n<nils@goers.line.org>*n*nAWNPipe © by William Parker*n<bill@amitrix.com>" "OK"`'
  194.         CALL ShellResult(requesterdata)
  195.  
  196.     END
  197.     IF in2 = 0 & in3 = 1 THEN DO
  198.         requesterdata='`requestchoice "T.H.E." "'localestring(MSG_Request_Quit)'" "'localestring(MSG_Request_Yes)'" PUBSCREEN='pubscreen'`'
  199.         IF ShellResult(requesterdata) = 1 THEN EXIT
  200.     END
  201.  
  202.     IF in2 = 1 & in3 = 0 THEN DO
  203.         IF currentpage = 1 THEN DO
  204.             IF hk_counter >0 THEN DO
  205.                 call topipe('id' HK_ListviewID 'removenode')
  206.                 CALL HKClearStrings()
  207.                 hk_entries = ""
  208.                 hk_counter = 0
  209.             END
  210.         END
  211.         ELSE DO
  212.             IF tm_counter >0 THEN DO
  213.                 call topipe('id' TM_ListviewID 'removenode')
  214.                 CALL TMClearStrings()
  215.                 tm_entries = ""
  216.                 tm_counter = 0
  217.             END
  218.         END
  219.     END
  220.     IF in2 = 1 & in3 = 1 THEN DO
  221.         IF currentpage = 1 THEN DO
  222.             call topipe('id' HK_ListviewID 'removenode')
  223.             hk_entries = ""
  224.             hk_counter = 0
  225.             call GetHotkeys()
  226.         END
  227.         IF currentpage = 0 THEN DO
  228.             call topipe('id' TM_ListviewID 'removenode')
  229.             tm_entries = ""
  230.             tm_counter = 0
  231.             call GetToolsMenu()
  232.         END
  233.     END
  234. RETURN
  235.  
  236. Gadget:
  237. SELECT
  238. /*
  239. *** ListView
  240. */
  241.     WHEN in2 = pageid THEN currentpage = in3
  242.  
  243.     WHEN in2 = TM_ListViewID  THEN DO
  244.         TM_currentnode=in5    /* remember the curently selected node for future use...*/
  245.         CALL _UpdateTMStrings(in5)
  246.     END
  247.  
  248.     WHEN in2 = HK_ListViewID  THEN DO
  249.         HK_currentnode=in5    /* remember the curently selected node for future use...*/
  250.         IF FIND(HK_entries,HK_currentnode) = 0 THEN RETURN
  251.  
  252.         /* update gui for current node */
  253.         call topipe('id 'HK_StringNameID' gt "'HK_name.in5'" ref')
  254.         call topipe('id 'HK_StringHotKeyID' gt "'HK_Key.in5'" ref')
  255.         call topipe('id 'HK_GetFileID' fn "'HK_command.in5'" ref')
  256.         call topipe('id 'HK_StringArgsID' gt "'HK_Args.in5'" ref')
  257.         IF HK_Key.in5 = "" THEN HK_HotkeyValue = ""
  258.                 ELSE HK_HotkeyValue = HK_Key.in5
  259.         
  260.     END
  261.  
  262. /*
  263. *** ToolsMenu Gadgets
  264. */
  265.     WHEN in2 = TM_AddID THEN DO
  266.         Node_ID = topipe('id 'TM_ListViewID 'addnode gt "'localestring(MSG_New_Name)'|'localestring(MSG_New_Title)'||rexx:" page 'pageid)
  267.         mt_Name = localestring(MSG_New_Name)
  268.         mt_Title = localestring(MSG_New_Title)
  269.         mt_ShortCut = ""
  270.         mt_Command = "rexx:"
  271.         mt_Args = ""
  272.         CALL WriteTMStem()
  273.  
  274.         TM_CURRENTNODE=Node_ID
  275.         call topipe2('id 'TM_ListViewID' s 'TM_CURRENTNODE)
  276.         CALL _UpdateTMStrings(TM_CURRENTNODE)
  277.  
  278. /*        call topipe('id 'TM_StringNameID' s=0')*/ /* auto activation forces system-crash */
  279.     END
  280.  
  281.     WHEN in2 = TM_RemoveID THEN DO
  282.     IF TM_currentnode = "TM_CURRENTNODE" THEN RETURN
  283.         IF topipe2('id 'TM_currentnode' address') = 0 THEN RETURN    /* check if GID exists */
  284.  
  285.         CALL topipe('id' TM_currentnode 'removenode')
  286.         CALL TMClearStrings()
  287.  
  288.         TM_counter = TM_counter - 1
  289.         TM_entries = DELWORD(TM_entries,FIND(TM_entries,TM_currentnode),1)
  290.     END
  291.  
  292.     WHEN in2 = TM_UpID THEN DO
  293.         IF TM_CURRENTNODE = "TM_CURRENTNODE" THEN RETURN
  294.         IF topipe2('id 'TM_currentnode' address') = 0 THEN RETURN    /* check if GID exists */
  295.  
  296.         currentPos = FIND(TM_entries,TM_currentnode)
  297.         prevEntry = WORD(TM_entries,currentPos-1)     /* get previous entry */
  298.         IF prevEntry = "" THEN RETURN            /* Top of list */
  299.  
  300.         CALL swapTM
  301.  
  302.         TM_CURRENTNODE = prevEntry
  303.         call topipe2('id 'TM_ListViewID' s 'TM_CURRENTNODE)
  304.         CALL _UpdateTMStrings(TM_currentnode)
  305.  
  306.     END
  307.  
  308.     WHEN in2 = TM_DownID THEN DO
  309.         IF TM_CURRENTNODE = "TM_CURRENTNODE" THEN RETURN
  310.         IF topipe2('id 'TM_currentnode' address') = 0 THEN RETURN    /* check if GID exists */
  311.  
  312.         currentPos = FIND(TM_entries,TM_currentnode)
  313.         prevEntry = WORD(TM_entries,currentPos+1)     /* get previous entry */
  314.         IF prevEntry = "" THEN RETURN            /* Top of list */
  315.         CALL swapTM
  316.         TM_CURRENTNODE = prevEntry
  317.         call topipe2('id 'TM_ListViewID' s 'TM_CURRENTNODE)
  318.         CALL _UpdateTMStrings(TM_currentnode)
  319.     END
  320.  
  321.  
  322. /*
  323. *** get Stringgadget value for Tools-Menu
  324. */
  325.     WHEN in2 = TM_StringNameID THEN DO
  326.         IF TM_currentnode = "TM_CURRENTNODE" THEN TM_currentnode = -1
  327.         TM_StringNameValue = DELWORD(in,1,2)
  328.  
  329.         IF TM_Args.TM_currentnode ~= "" THEN commandArgs = TM_Command.TM_currentnode TM_Args.TM_currentnode
  330.                         ELSE commandArgs = TM_Command.TM_currentnode||TM_Args.TM_currentnode
  331.  
  332.         IF topipe2('id 'TM_currentnode' address') ~= 0 THEN    /* check if GID exists */
  333.             call topipe('id 'TM_currentnode' gt "'TM_StringNameValue'|'TM_title.TM_currentnode'|'TM_ShortCut.TM_currentnode'|'commandArgs'"')
  334.             TM_Name.TM_currentnode = TM_StringNameValue
  335.     END
  336.     WHEN in2 = TM_StringTitleID THEN DO
  337.         IF TM_currentnode = "TM_CURRENTNODE" THEN TM_currentnode = -1
  338.         TM_StringTitleValue = DELWORD(in,1,2)
  339.         IF TM_Args.TM_currentnode ~= "" THEN commandArgs = TM_Command.TM_currentnode TM_Args.TM_currentnode
  340.                         ELSE commandArgs = TM_Command.TM_currentnode||TM_Args.TM_currentnode
  341.         IF topipe2('id 'TM_currentnode' address') ~= 0 THEN    /* check if GID exists */
  342.             call topipe('id 'TM_currentnode' gt "'TM_Name.TM_currentnode'|'TM_StringTitleValue'|'TM_ShortCut.TM_currentnode'|'commandArgs'"')
  343.             TM_Title.TM_currentnode = TM_StringTitleValue
  344.     END
  345.     WHEN in2 = TM_StringShortcutID THEN DO
  346.         IF TM_currentnode = "TM_CURRENTNODE" THEN TM_currentnode = -1
  347.         IF LENGTH(in3) > 0 THEN in3 = LEFT(in3,1)
  348.                     ELSE in3 = ""
  349.         TM_StringShortcutValue = in3
  350.         IF TM_Args.TM_currentnode ~= "" THEN commandArgs = TM_Command.TM_currentnode TM_Args.TM_currentnode
  351.                         ELSE commandArgs = TM_Command.TM_currentnode||TM_Args.TM_currentnode
  352.         IF topipe2('id 'TM_currentnode' address') ~= 0 THEN    /* check if GID exists */
  353.             call topipe('id 'TM_currentnode' gt "'TM_Name.TM_currentnode'|'TM_title.TM_currentnode'|'TM_StringShortCutValue'|'commandArgs'"')
  354.             call topipe('id 'TM_StringShortCutID 'gt "'TM_StringShortcutValue'" ref')
  355.             TM_ShortCut.TM_currentnode = TM_StringShortCutValue
  356.     END
  357.     WHEN in2 = TM_GetFileID THEN DO
  358.         IF TM_currentnode = "TM_CURRENTNODE" THEN TM_currentnode = -1
  359.         TM_StringCommandValue = STRIP(COMPRESS(DELWORD(in,1,3),'"'))
  360.         IF TM_Args.TM_currentnode ~= "" THEN commandArgs = TM_StringCommandValue TM_Args.TM_currentnode
  361.                         ELSE commandArgs = TM_StringCommandValue||TM_Args.TM_currentnode
  362.         IF topipe2('id 'TM_currentnode' address') ~= 0 THEN    /* check if GID exists */
  363.             call topipe('id 'TM_currentnode' gt "'TM_Name.TM_currentnode'|'TM_title.TM_currentnode'|'TM_ShortCut.TM_currentnode'|'commandArgs'"')
  364.             TM_Command.TM_currentnode = TM_StringCommandValue
  365.     END
  366.     WHEN in2 = TM_StringArgsID THEN DO
  367.         IF TM_currentnode = "TM_CURRENTNODE" THEN TM_currentnode = -1
  368.         TM_StringArgsValue = STRIP(COMPRESS(DELWORD(in,1,2),'"'))
  369.         IF TM_StringArgsValue ~= "" THEN commandArgs = TM_Command.TM_currentnode TM_StringArgsValue
  370.                         ELSE commandArgs = TM_Command.TM_currentnode||TM_StringArgsValue
  371.         IF topipe2('id 'TM_currentnode' address') ~= 0 THEN    /* check if GID exists */
  372.             call topipe('id 'TM_currentnode' gt "'TM_Name.TM_currentnode'|'TM_title.TM_currentnode'|'TM_ShortCut.TM_currentnode'|'commandArgs'"')
  373.             TM_Args.TM_currentnode = TM_StringArgsValue
  374.     END
  375.  
  376. /*
  377. *** Hotkey Gadgets
  378. */
  379.     WHEN in2 = HK_AddID THEN DO
  380.         Node_ID = topipe('id 'HK_ListViewID 'addnode gt "'localestring(MSG_New_Name)'|'localestring(MSG_New_Hotkey)'|rexx:" page 'pageid)
  381.  
  382.         hk_Name = localestring(MSG_New_Name)
  383.         hk_key = ""
  384.         hk_Command = "rexx:"
  385.         CALL WriteHKStem()
  386.         HK_CURRENTNODE=Node_ID
  387.         call topipe2('id 'HK_ListViewID' s 'HK_CURRENTNODE)
  388.  
  389.         /* update gui for current node */
  390.         call topipe('id 'HK_StringNameID' gt "'HK_name.HK_CURRENTNODE'" ref')
  391.         call topipe('id 'HK_StringHotKeyID' gt "'HK_Key.HK_CURRENTNODE'" ref')
  392.         call topipe('id 'HK_GetFileID' fn "'HK_command.HK_CURRENTNODE'" ref')
  393.         call topipe('id 'HK_StringArgsID' gt "'HK_Args.HK_CURRENTNODE'" ref')
  394.         IF HK_Key.HK_CURRENTNODE = "" THEN HK_HotkeyValue = ""
  395.                 ELSE HK_HotkeyValue = HK_Key.HK_CURRENTNODE
  396.  
  397. /*        call topipe('id 'HK_StringNameID' s=0')*/ /* auto activation forces system-crash */
  398.  
  399.     END
  400.  
  401.     WHEN in2 = HK_RemoveID THEN DO
  402.     IF HK_currentnode = "HK_CURRENTNODE" THEN RETURN
  403.         IF topipe2('id 'HK_currentnode' address') = 0 THEN RETURN    /* check if GID exists */
  404.         CALL topipe('id' HK_currentnode 'removenode')
  405.         CALL HKClearStrings()
  406.  
  407.         HK_counter = HK_counter - 1
  408.         HK_entries = DELWORD(HK_entries,FIND(HK_entries,HK_currentnode),1)
  409.     END
  410.  
  411. /*
  412. *** get Stringgadget value for Hotkeys
  413. */
  414.     WHEN in2 = HK_StringNameID THEN DO
  415.         IF HK_currentnode = "HK_CURRENTNODE" THEN HK_currentnode = -1
  416.         HK_StringNameValue = DELWORD(in,1,2)
  417.         IF HK_Args.HK_currentnode ~= "" THEN commandArgs = HK_Command.HK_currentnode HK_Args.HK_currentnode
  418.                         ELSE commandArgs = HK_Command.HK_currentnode||HK_Args.HK_currentnode
  419.         IF topipe2('id 'HK_currentnode' address') ~= 0 THEN    /* check if GID exists */
  420.             call topipe('id 'HK_currentnode' gt "'HK_StringNameValue'|'HK_Key.HK_currentnode'|'commandArgs'"')
  421.         HK_Name.HK_currentnode = HK_StringNameValue
  422.     END
  423.  
  424.     WHEN in2 = HK_CancelBoxID THEN DO
  425.         IF HK_currentnode = "HK_CURRENTNODE" THEN HK_currentnode = -1
  426.  
  427.         call topipe('id 'HK_StringHotKeyID 'gt "" ref')
  428.  
  429.         IF topipe2('id 'HK_currentnode' address') ~= 0 THEN DO/* check if GID exists */
  430.             call topipe('id 'HK_currentnode' gt "'HK_name.HK_currentnode'|""|'commandArgs'"')
  431.             HK_Key.HK_currentnode = ""
  432.         END
  433.         HK_StringHotkeyValue = ""
  434.     END
  435.  
  436.     WHEN in2 = HK_StringHotKeyID THEN DO
  437.     in3 = DELWORD(in,1,2)
  438.         IF HK_currentnode = "HK_CURRENTNODE" THEN HK_currentnode = -1
  439.         IF in3 = "" THEN HK_StringHotkeyValue = ""
  440.                 ELSE HK_StringHotkeyValue = in3
  441.         IF HK_Args.HK_currentnode ~= "" THEN commandArgs = HK_Command.HK_currentnode HK_Args.HK_currentnode
  442.                         ELSE commandArgs = HK_Command.HK_currentnode||HK_Args.HK_currentnode
  443.         call topipe('id 'HK_StringHotKeyID' gt "'HK_StringHotkeyValue'" ref')
  444.         IF topipe2('id 'HK_currentnode' address') ~= 0 THEN /* check if GID exists */
  445.             call topipe('id 'HK_currentnode' gt "'HK_name.HK_currentnode'|'HK_StringHotkeyValue'|'commandArgs'"')
  446.  
  447.         HK_Key.HK_currentnode = HK_StringHotKeyValue
  448.     END
  449.  
  450.     WHEN in2 = HK_chooserID THEN DO
  451.         addHotkey = WORD(TRANSLATE(Hotkeys," ","|"),in3+1)
  452.         IF HK_currentnode ~= "HK_CURRENTNODE" & HK_currentnode ~= -1 THEN HK_StringHotkeyValue = HK_Key.HK_currentnode
  453.                             ELSE HK_CURRENTNODE = -1
  454.  
  455.         IF HK_StringHotkeyValue = "" THEN HK_StringHotkeyValue = addhotkey
  456.                   ELSE HK_StringHotkeyValue = HK_StringHotkeyValue ||" "|| addHotkey
  457.  
  458.         IF HK_Args.HK_currentnode ~= "" THEN commandArgs = HK_Command.HK_currentnode HK_Args.HK_currentnode
  459.                         ELSE commandArgs = HK_Command.HK_currentnode||HK_Args.HK_currentnode
  460.  
  461.         call topipe('id 'HK_StringHotKeyID 'gt "'HK_StringHotkeyValue'"')
  462.  
  463.         IF topipe2('id 'HK_currentnode' address') ~= 0 THEN    /* check if GID exists */
  464.             call topipe('id 'HK_currentnode' gt "'HK_Name.HK_currentnode'|'HK_StringHotkeyValue'|'commandArgs'"')
  465.             HK_Key.HK_currentnode = HK_StringHotKeyValue
  466.     END
  467.  
  468.     WHEN in2 = HK_GetFileID THEN DO
  469.         IF HK_currentnode = "HK_CURRENTNODE" THEN HK_currentnode = -1
  470.         HK_StringCommandValue = STRIP(COMPRESS(DELWORD(in,1,3),'"'))
  471.         IF HK_Args.HK_currentnode ~= "" THEN commandArgs = HK_StringCommandValue HK_Args.HK_currentnode
  472.                         ELSE commandArgs = HK_StringCommandValue||HK_Args.HK_currentnode
  473.         IF topipe2('id 'HK_currentnode' address') ~= 0 THEN    /* check if GID exists */
  474.             call topipe('id 'HK_currentnode' gt "'HK_Name.HK_currentnode'|'HK_Key.HK_currentnode'|'commandArgs'"')
  475.             HK_Command.HK_currentnode = HK_StringCommandValue
  476.     END
  477.     WHEN in2 = HK_StringArgsID THEN DO
  478.         IF HK_currentnode = "HK_CURRENTNODE" THEN HK_currentnode = -1
  479.         HK_StringArgsValue = STRIP(COMPRESS(DELWORD(in,1,2),'"'))
  480.         IF HK_StringArgsValue ~= "" THEN commandArgs = HK_Command.HK_currentnode HK_StringArgsValue
  481.                         ELSE commandArgs = HK_Command.HK_currentnode||HK_StringArgsValue
  482.         IF topipe2('id 'HK_currentnode' address') ~= 0 THEN    /* check if GID exists */
  483.             call topipe('id 'HK_currentnode' gt "'HK_Name.HK_currentnode'|'HK_Key.HK_currentnode'|'commandArgs'"')
  484.             HK_Args.HK_currentnode = HK_StringArgsValue
  485.     END
  486. /*
  487. *** Save|Use|Cancel gadgets
  488. */
  489.     WHEN in2 = TM_SaveID | in2 = HK_SaveID THEN DO
  490.         CALL _Save
  491.         CALL _RemoveMenuHotkeys
  492.         RX scriptname
  493.         EXIT
  494.     END
  495.     WHEN in2 = TM_UseID | in2 = HK_UseID THEN DO
  496.         CALL _RemoveMenuHotkeys
  497.         Scriptname.bak = Scriptname
  498.         Scriptname = "t:myscript"
  499.         CALL _Save
  500.         RX scriptname
  501.         IF exists(scriptname) THEN DELETE scriptname
  502.         Scriptname = Scriptname.bak
  503.         EXIT
  504.     END
  505.  
  506.     WHEN in2 = TM_CancelID | in2 = HK_CancelID THEN EXIT()
  507.  
  508. OTHERWISE
  509. NOP
  510. END
  511. return
  512.  
  513. BuildGUI:
  514. /* define window */
  515. call topipe('Title="'localestring(MSG_TitleName)'" st="Workbench Screen" Icontitle=THE iconifygadget defaultgadgets modify verticaly SpaceInner SpaceOuter topleft activate ii "'called'" pubscreen='pubscreen)
  516.  
  517. /* define the menues */
  518. call topipe('menu gt "'localestring(MSG_MenuT_Project)'|'localestring(MSG_Menu_About)'|'localestring(MSG_Menu_Quit)'"')
  519. call topipe('menu gt "'localestring(MSG_MenuT_Edit)'|'localestring(MSG_Menu_Remove)'|'localestring(MSG_Menu_LastSaved)'"')
  520.  
  521. /* define the gadgets*/
  522. pageid = topipe('clicktab ctl "'localestring(MSG_MAIN_ToolsMenu)'|'localestring(MSG_MAIN_HotkeyMenu)'"')
  523.  
  524. call topipe('layout b=0 v page' pageid)
  525. call topipe('layout si so gt='localestring(MSG_TM_ToolsMenu))
  526. TM_ListViewID = topipe('listbrowser lbl="'localestring(MSG_TM_LV_Title)'" arrows vert hori minh=120 minw=300 showtitles')
  527. call topipe(le)
  528.  
  529. call topipe('layout hori so b=0 weih=0')
  530. TM_AddID = topipe('button gt "'localestring(MSG_Button_Add)'"')
  531. call topipe('space')
  532. TM_RemoveID = topipe('button gt "'localestring(MSG_Button_Remove)'"')
  533. call topipe('space')
  534. TM_UpID = topipe('button gt "'localestring(MSG_Button_Up)'"')
  535. call topipe('space')
  536. TM_DownID = topipe('button gt "'localestring(MSG_Button_Down)'"')
  537. call topipe(le)
  538.  
  539. call topipe('layout v si so weih 0')
  540. call topipe('label gt "'localestring(MSG_String_Name)'" ua')
  541. TM_StringNameID = topipe('string chl lj tc')
  542. call topipe('label gt "'localestring(MSG_String_Title)'" ua')
  543. TM_StringTitleID = topipe('string chl lj tc')
  544. call topipe('label gt "'localestring(MSG_String_ShortCut)'" ua')
  545. TM_StringShortCutID = topipe('string chl lj tc maxchars=3')
  546. call topipe('label gt "'localestring(MSG_String_Command)'" ua')
  547. TM_GetFileID = topipe('getfile chl fn "rexx:"')
  548. call topipe('label gt "'localestring(MSG_String_Argument)'" ua')
  549. TM_StringArgsID = topipe('string chl lj tc')
  550. call topipe(le)
  551.  
  552. call topipe('layout b=0 v si so weih 0')
  553. call topipe('button b=7 minh 2')
  554. call topipe('layout b=0 h si so weih 0')
  555. TM_SaveID = topipe('button weiw 0 gt "'localestring(MSG_Button_Save)'"')
  556. call topipe('space')
  557. TM_UseID = topipe('button weiw 0 gt "'localestring(MSG_Button_Use)'"')
  558. call topipe('space')
  559. TM_CancelID = topipe('button weiw 0 gt "'localestring(MSG_Button_Cancel)'"')
  560. call topipe(le)
  561. call topipe(le)
  562. call topipe(le)
  563.  
  564. call topipe('layout b 0 v page' pageid)
  565. call topipe('layout si so gt="'localestring(MSG_HK_Hotkey)'"')
  566. HK_ListViewID = topipe('listbrowser lbl="'localestring(MSG_HK_LV_Title)'" arrows vert hori minh=120 minw=300 showtitles')
  567. call topipe(le)
  568.  
  569. call topipe('layout hori so b=0 weih=0')
  570. HK_AddID = topipe('button gt "'localestring(MSG_Button_Add)'"')
  571. call topipe('space')
  572. HK_RemoveID = topipe('button gt "'localestring(MSG_Button_Remove)'"')
  573. call topipe(le)
  574.  
  575. call topipe('layout v si so weih 0')
  576. call topipe('label gt "'localestring(MSG_String_Name)'" ua')
  577. HK_StringNameID = topipe('string chl lj tc')
  578. call topipe('label gt "'localestring(MSG_String_HotKey)'" ua')
  579. call topipe('layout chl bj b=0')
  580.  
  581. HK_StringHotKeyID = topipe('string chl lj tc')
  582. HK_CancelBoxID = topipe('button autobutton=4 weiw=0')
  583. HK_ChooserID = topipe('chooser chl lj maxn=21 cl='hotkeys)
  584. call topipe('le')
  585. call topipe('label gt "'localestring(MSG_String_Command)'" ua')
  586. HK_GetFileID = topipe('getfile chl fn "rexx:"')
  587. call topipe('label gt "'localestring(MSG_String_Argument)'" ua')
  588. HK_StringArgsID = topipe('string chl lj tc')
  589. call topipe(le)
  590.  
  591. call topipe('layout b=0 v si so weih 0')
  592. call topipe('button b=7 minh 2')
  593. call topipe('layout b=0 h si so weih 0')
  594. HK_SaveID = topipe('button weiw 0 gt "'localestring(MSG_Button_Save)'"')
  595. call topipe('space')
  596. HK_UseID =  topipe('button weiw 0 gt "'localestring(MSG_Button_Use)'"')
  597. call topipe('space')
  598. HK_CancelID = topipe('button weiw 0 gt "'localestring(MSG_Button_Cancel)'"')
  599. call topipe(le)
  600. call topipe(le)
  601.  
  602. /*open the GUI window*/
  603. call topipe("open")
  604.  
  605. /* now create the listview entries */
  606. call GetToolsMenu()
  607. call GetHotkeys()
  608. RETURN
  609.  
  610.  
  611. topipe:
  612. /* this routine does error checking on lines written to pipe.*/
  613. /*get line to output*/
  614. parse arg out
  615.  
  616. /* write to the pipe*/
  617. call writeln(ca,out)
  618.  
  619. /*get responce and parse it.*/
  620. in=readln(ca)
  621. parse var in res1 res2 .
  622.  
  623. /* if all is ok return the second part of the responce (usualy the GID)*/
  624. if res1='ok' then return(res2)
  625.  
  626. /* something went wrong, we notify the user then exit */
  627. /*show problem line and responce (reponce may be just a blank line)*/
  628. say 'error from: 'out
  629. say '  responce: ' in
  630. exit
  631.  
  632. topipe2:
  633. /* this routine does error checking on lines written to pipe.*/
  634.  
  635. /*get line to output*/
  636. parse arg out
  637.  
  638. /* write to the pipe*/
  639. call writeln(ca,out)
  640.  
  641. /*get responce and parse it.*/
  642. in=readln(ca)
  643. parse var in res1 res2 .
  644.  
  645. return(res1)
  646.  
  647. /*
  648. */
  649. GetToolsMenu:
  650. GETATTR MENUCOMMANDS.COUNT
  651. ToolsMenu.0 = result
  652.  
  653. call topipe('id 'TM_ListViewID 'list 0')
  654.  
  655. DO i = 0 to ToolsMenu.0 -1
  656.     GETATTR MENUCOMMANDS.i.NAME
  657.     mt_name = result
  658.     GETATTR MENUCOMMANDS.i.TITLE
  659.     mt_title = result
  660.     GETATTR MENUCOMMANDS.i.SHORTCUT
  661.     mt_shortcut = result
  662.     GETATTR MENUCOMMANDS.i.COMMAND
  663.     mt_command = result
  664.     /* get the GID of the node, save the contents of the node for further reference. */
  665.     Node_ID = topipe('id 'TM_ListViewID 'addnode gt "'mt_name'|'mt_title'|'mt_shortcut'|'mt_command'" page 'pageid)
  666.  
  667.     CALL WriteTMStem()
  668. END
  669. call topipe('id 'TM_ListViewID 'list 1 page' pageid)
  670. RETURN
  671.  
  672. GetHotkeys:
  673. GETATTR KEYCOMMANDS.COUNT
  674. Hotkeys.0 = result
  675. call topipe('id 'HK_ListViewID 'list 0')
  676. DO i = 0 to Hotkeys.0 -1
  677.     GETATTR KEYCOMMANDS.i.NAME
  678.     hk_name = result
  679.     GETATTR KEYCOMMANDS.i.KEY
  680.     hk_key = result
  681.     GETATTR KEYCOMMANDS.i.COMMAND
  682.     hk_command = result
  683.  
  684.     /* get the GID of the node, save the contents of the node for further reference. */
  685.     Node_ID = topipe('id 'HK_ListViewID 'addnode gt "'hk_name'|'hk_key'|'hk_command'" page 'pageid)
  686.     call writeHKStem()
  687. END
  688. call topipe('id 'HK_ListViewID 'list 1 page' pageid)
  689. RETURN
  690.  
  691. WriteTMStem:
  692.     TM_name.Node_ID=mt_name
  693.     TM_title.Node_ID=mt_title
  694.     TM_Shortcut.Node_ID=mt_shortcut
  695.     call parseTMArgs()            /* write command and args */
  696.  
  697.     TM_counter = TM_counter + 1
  698.     TM_Entries = TM_Entries Node_ID        /* add GID to TM_entries */
  699. RETURN
  700.  
  701. TMClearStrings:
  702.     CALL topipe('id 'TM_StringNameID 'gt ""')
  703.     CALL topipe('id 'TM_StringTitleID 'gt ""')
  704.     CALL topipe('id 'TM_StringShortCutID 'gt ""')
  705.     CALL topipe('id 'TM_GetFileID 'fn "rexx:"')
  706.     CALL topipe('id 'TM_StringArgsID 'gt ""')
  707.     TM_StringNameValue    = ""
  708.     TM_StringTitleValue    = ""
  709.     TM_StringShortcutValue    = ""
  710.     TM_StringCommandValue    = "rexx:"
  711.     TM_StringArgsValue    = ""
  712. RETURN
  713.  
  714. WriteHKStem:
  715.     HK_Name.Node_ID = HK_name
  716.     HK_Key.Node_ID = HK_Key
  717.     call parseHKArgs()            /* write command and args */
  718.  
  719.     HK_counter = HK_counter + 1
  720.     HK_Entries = HK_Entries Node_ID        /* add GID to HK_entries */
  721. RETURN
  722.  
  723. HKClearStrings:
  724.     CALL topipe('id 'HK_StringNameID 'gt ""')
  725.     CALL topipe('id 'HK_StringHotKeyID 'gt ""')
  726.     CALL topipe('id 'HK_GetFileID 'fn "rexx:"')
  727.     CALL topipe('id 'HK_StringArgsID 'gt ""')
  728.     HK_StringNameValue    = ""
  729.     HK_StringHotKeyValue    = ""
  730.     HK_StringCommandValue    = "rexx:"
  731.     HK_StringArgsValue    = ""
  732.  
  733. RETURN
  734.  
  735. _Save:
  736. IF TM_counter = 0 & HK_counter = 0 THEN RETURN
  737. CALL OPEN(file,scriptname,write)
  738. CALL WRITELN(file,"/*"localestring(MSG_Created)" T.H.E.*/"||NL||"ADDRESS WORKBENCH")
  739.  
  740. IF HK_counter >0 THEN DO
  741.     DO i = 1 to WORDS(HK_entries)
  742.         val = WORD(HK_entries,i)
  743.         IF HK_Args.val ~= "" THEN commandArgs = HK_Command.val HK_Args.val
  744.                         ELSE commandArgs = HK_Command.val||HK_Args.val
  745.         CALL WRITELN(file,KEYBOARD ADD NAME '''"'||HK_Name.val||'"''' KEY '''"'||HK_Key.val||'"''' CMD '"'||commandArgs||'"')
  746.     END
  747. END
  748.  
  749. IF TM_counter >0 THEN DO
  750. CALL WRITELN(file,"")
  751.     DO i = 1 to WORDS(tm_entries)
  752.         val = WORD(tm_entries,i)
  753.         IF TM_Args.val ~= "" THEN commandArgs = TM_Command.val TM_Args.val
  754.                         ELSE commandArgs = TM_Command.val||TM_Args.val
  755.  
  756.     IF TM_Shortcut.val = "" THEN CALL WRITELN(file,MENU ADD NAME '''"'||TM_name.val||'"''' TITLE '''"'||TM_title.val||'"''' CMD '"'||commandArgs||'"')
  757.                     ELSE CALL WRITELN(file,MENU ADD NAME '''"'||TM_name.val||'"''' TITLE '''"'||TM_title.val||'"''' SHORTCUT '"'||TM_Shortcut.val||'"' CMD '"'||commandArgs||'"')
  758.         END
  759. END
  760. CALL CLOSE(file)
  761. RETURN
  762.  
  763. _RemoveMenuHotkeys:
  764.     GETATTR KEYCOMMANDS.COUNT
  765.     clearkey = result
  766.     DO i = clearKey - 1 to 0 BY - 1
  767.         GETATTR KEYCOMMANDS.i.NAME
  768.         name1 = result
  769.         KEYBOARD NAME name1 REMOVE
  770.     END
  771.  
  772.     GETATTR MENUCOMMANDS.COUNT
  773.     clearMenu = result
  774.     DO i = clearMenu - 1 to 0 BY - 1
  775.         GETATTR MENUCOMMANDS.i.NAME
  776.         name1 = result
  777.         MENU NAME name1 REMOVE
  778.     END
  779. RETURN
  780.  
  781. _UpdateTMStrings:
  782. PARSE ARG val
  783. /* update gui for current node */
  784. IF FIND(tm_entries,TM_currentnode) = 0 THEN RETURN
  785. call topipe('id 'TM_StringNameID' gt "'TM_name.val'" ref')
  786. call topipe('id 'TM_StringTitleID' gt "'TM_title.val'" ref')
  787. call topipe('id 'TM_StringShortcutID' gt "'TM_shortcut.val'" ref')
  788. call topipe('id 'TM_GetFileID' fn "'TM_command.val'" ref')
  789. call topipe('id 'TM_StringArgsID' gt "'TM_Args.val'" ref')
  790. RETURN
  791.  
  792. SwapTM:
  793. TM_name.bak1 = TM_Name.prevEntry
  794. TM_name.bak2 = TM_Name.TM_currentnode
  795. TM_Title.bak1 = TM_Title.prevEntry 
  796. TM_Title.bak2 = TM_Title.TM_currentnode 
  797. TM_ShortCut.bak1 = TM_ShortCut.prevEntry
  798. TM_ShortCut.bak2 = TM_ShortCut.TM_currentnode
  799. TM_Command.bak1 = TM_Command.prevEntry
  800. TM_Command.bak2 = TM_Command.TM_currentnode
  801. TM_Args.bak1 = TM_Args.prevEntry
  802. TM_Args.bak2 = TM_Args.TM_currentnode
  803.  
  804. TM_Name.prevEntry        = TM_name.bak2
  805. TM_Name.TM_currentnode        = TM_name.bak1
  806. TM_Title.prevEntry        = TM_Title.bak2
  807. TM_Title.TM_currentnode        = TM_Title.bak1
  808. TM_ShortCut.prevEntry        = TM_ShortCut.bak2
  809. TM_ShortCut.TM_currentnode    = TM_ShortCut.bak1
  810. TM_Command.prevEntry        = TM_Command.bak2
  811. TM_Command.TM_currentnode    = TM_Command.bak1
  812. TM_Args.prevEntry        = TM_Args.bak2
  813. TM_Args.TM_currentnode        = TM_Args.bak1
  814.  
  815. call topipe2('id 'TM_ListViewID' list 0')
  816. IF TM_Args.TM_currentnode ~= "" THEN commandArgs = TM_Command.TM_currentnode TM_Args.TM_currentnode
  817.                 ELSE commandArgs = TM_Command.TM_currentnode||TM_Args.TM_currentnode
  818. call topipe('id 'TM_currentnode' gt "'TM_Name.TM_currentnode'|'TM_title.TM_currentnode'|'TM_ShortCut.TM_currentnode'|'commandArgs'"')
  819.  
  820. IF TM_Args.prevEntry    ~= "" THEN commandArgs = TM_Command.prevEntry TM_Args.prevEntry
  821.                 ELSE commandArgs = TM_Command.prevEntry||TM_Args.prevEntry
  822. call topipe('id 'prevEntry' gt "'TM_Name.prevEntry'|'TM_title.prevEntry'|'TM_ShortCut.prevEntry'|'commandArgs'"')
  823. call topipe2('id 'TM_ListViewID' list 1 page' pageid)
  824. RETURN
  825.  
  826. ShellResult:
  827. PARSE ARG ShellCmd
  828. cmdid='req'pragma('id')
  829. address command 'rxset' cmdid Shellcmd
  830. from_Shell=getclip(cmdid)
  831. call setclip(cmdid,'')
  832. RETURN(from_Shell)
  833.  
  834. parseTMArgs:
  835.     IF WORDS(mt_command) >1 THEN DO            /* more than one word? */
  836.         firstchar= INDEX(mt_command,":")
  837.         firstArg = INDEX(mt_command," ",firstchar)
  838.         IF firstArg = 0 THEN firstArg = 1
  839.             TM_command.Node_ID= SUBSTR(mt_command,1,firstArg-1)
  840.             TM_Args.Node_ID   = RIGHT(mt_command,LENGTH(mt_command)-firstArg)
  841.     END
  842.     ELSE DO
  843.         TM_command.Node_ID=mt_command
  844.         TM_Args.Node_ID   = ""
  845.     END
  846. RETURN
  847.  
  848. parseHKArgs:
  849.     IF WORDS(hk_command) >1 THEN DO            /* more than one word? */
  850.         firstchar= INDEX(hk_command,":")
  851.         firstArg = INDEX(hk_command," ",firstchar)
  852.             HK_command.Node_ID= SUBSTR(hk_command,1,firstArg-1)
  853.             HK_Args.Node_ID   = RIGHT(hk_command,LENGTH(hk_command)-firstArg)
  854.     END
  855.     ELSE DO
  856.         HK_command.Node_ID=hk_command
  857.         HK_Args.Node_ID   = ""
  858.     END
  859. RETURN
  860.